package com.yundao.dao;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by linving on 2017/3/7.
 */
public class BaseDao<T> {

    @Resource(name = "sessionFactory")
    private SessionFactory sessionFactory;


   public List<T> getList(Class<T> t) {
        Criteria criteria = getSession().createCriteria(t);
        return criteria.list();
    }


    public void save(T t) {
        getSession().save(t);
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public Session getSession() {
        return sessionFactory.getCurrentSession();
    }

}
